/*
 * @Description: 表格工具栏配置
 * @Author: HuiSir<https://gitee.com/huisir001>
 * @Date: 2025-07-28 21:55:31
 * @LastEditTime: 2025-09-15 18:06:49
 */
import { defineToolsOptions } from "@/components/TablePage/predefined";
import useEditOptions from "./useEditOptions";
import useSearchOptions from "./useSearchOptions";
import { addRole } from "@/api/sys";
import { project } from "@/init/config";
import { fieldMapping } from "@/utils/common";

export default defineToolsOptions((getPermTreeList: () => Awaitable<void>) => ({
  tools: ["add", "cols", "search", "export", "refresh"],
  searchFormParams: {},
  searchFormOptions: useSearchOptions(),
  addDialogProps: { title: "新增角色" },
  addFormOptions: useEditOptions(),
  beforeShowAddDialog: getPermTreeList,
  beforeAddSubmit(formData) {
    // 字段映射
    fieldMapping({
      data: formData.value,
      fieldsMap: project.roleFields,
      reverse: true,
    });
  },
  addRequest: addRole,
}));
